﻿using Project.API.Models.UsersModels;
using Project.BLL.UsersInfoBll;
using Project.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace Project.API.Controllers.UsersInfoController
{
    public class AddressController : ApiController
    {
        // GET: api/Address
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET: api/Address/5
        public List<AddressDto> Get(int id)
        {
            var data = new AddressBll().Query().Where(x => x.Uid == id);
            var list = from d in data
                       select new AddressDto
                       {
                           Sid = d.Sid,
                           Address = d.Address1,
                           Phone = d.Phone,
                           House = d.House,
                           username = d.user_info.username
                       };
            return list.ToList();


        }

        // POST: api/Address
        public Result Post([FromBody] Address value)
        {
            //添加用户地址
            bool bol = new AddressBll().Add(value);
            Result result = new Result()
            {
                code = bol ? 1 : 0,
                msg = bol ? "添加成功!" : "添加失败!"
            };
            return result;
        }

        // PUT: api/Address/5
        public void Put(int id, [FromBody] string value)
        {
        }

        // DELETE: api/Address/5
        public void Delete(int id)
        {
        }
    }
}
